package rpc.proxy;

import java.lang.reflect.Proxy;

public class ProxyUtil {

    public static Object getProxyInstance(Class<?> cls) {
        Object proxyInstance = null;
        Class<?>[] Interfaces = new Class[]{cls};
        MethodProxy invocationHandler = null;
        if(!cls.isInterface()){
            Interfaces = cls.getInterfaces();
            try {
                invocationHandler = new MethodProxy(cls.newInstance());
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
            }
        } else {
            invocationHandler = new MethodProxy();
        }
        proxyInstance = Proxy.newProxyInstance(  
                cls.getClassLoader(),  
                Interfaces, 
                invocationHandler); 
        return proxyInstance;
    }

}
